import {
    reactive,
    ref
} from "vue";
import { Message } from "@arco-design/web-vue";
import test from "@/utils/test";
const env = ref(import.meta.env);
export const form = ref({
    // 司机姓名
    driver_name: "",
    // 司机身份证号码
    drive_crad: "",
    // 手机号码
    mobile: "",
    // 所属用户
    dept_id: "",
    // 司机驾驶证
    driver_license: "",
    // 身份证正面
    card_front: "",
    // 身份证反面
    card_back: "",
    xingshizheng: "",
    jiashizheng: "",
    daoluxukezheng: "",
});

export const rules = reactive({
    driver_name: {
        required: true,
        message: "请输入姓名"
    },
    drive_crad: [{
            required: true,
            message: "请输入司机身份证号码"
        },
        {
            validator: (value, cd) => {
                if (!test.idCard(value)) {
                    cd("身份证格式错误");
                }
            },
        },
    ],
    mobile: [{
            required: true,
            message: "请输入手机号码"
        },
        {
            validator: (value, cd) => {
                if (!test.mobile(value)) {
                    cd("手机号格式错误");
                }
            },
        },
    ],
    dept_id: {
        required: true,
        message: "请选择公司名称"
    },
    // driver_license: {
    //     required: true,
    //     message: "请输入司机驾驶证"
    // },
});

export const c_f_file = ref();

export const c_b_file = ref();

export const c_f_change = (_, currentFile) => {
    c_f_file.value = {
        ...currentFile,
    };
};
export const c_f_progress = (currentFile) => {
    c_f_file.value = currentFile;
};
export const c_f_success = (e) => {

    console.log(e);
    if(e.response.code == 200){
        form.value.card_front = (env.value.VITE_APP_OPEN_PROXY === 'true'? env.value.VITE_APP_BASE_URL : env.value.VITE_APP_BASE_URL) + e.response.data.url;
    }else{
        Message.error(e.response.message); 
    }
    
};

export const c_b_change = (_, currentFile) => {
    c_b_file.value = {
        ...currentFile,
    };
};
export const c_b_progress = (currentFile) => {
    c_b_file.value = currentFile;
};
export const c_b_success = (e) => {
    if(e.response.code == 200){
        form.value.card_back = (env.value.VITE_APP_OPEN_PROXY === 'true'? env.value.VITE_APP_BASE_URL : env.value.VITE_APP_BASE_URL) + e.response.data.url;
    }else{
        Message.error(e.response.message); 
    }
    
};

export const l_file = ref();

export const l_change = (_, currentFile) => {
    l_file.value = {
        ...currentFile,
    };
};
export const l_progress = (currentFile) => {
    l_file.value = currentFile;
};
export const l_success = (e) => {
    form.value.driver_license = (env.value.VITE_APP_OPEN_PROXY === 'true'? env.value.VITE_APP_BASE_URL : env.value.VITE_APP_BASE_URL) + e.response.data.url;
};

export const xsz_file = ref();

export const xsz_change = (_, currentFile) => {
    xsz_file.value = {
        ...currentFile,
    };
};
export const xsz_progress = (currentFile) => {
    xsz_file.value = currentFile;
};
export const xsz_success = (e) => {
    form.value.xingshizheng = (env.value.VITE_APP_OPEN_PROXY === 'true'? env.value.VITE_APP_BASE_URL : env.value.VITE_APP_BASE_URL) + e.response.data.url;
};


export const jsz_file = ref();

export const jsz_change = (_, currentFile) => {
    jsz_file.value = {
        ...currentFile,
    };
};
export const jsz_progress = (currentFile) => {
    jsz_file.value = currentFile;
};
export const jsz_success = (e) => {
    if(e.response.code == 200){
        form.value.jiashizheng = (env.value.VITE_APP_OPEN_PROXY === 'true'? env.value.VITE_APP_BASE_URL : env.value.VITE_APP_BASE_URL) + e.response.data.url;
    }else{
        Message.error(e.response.message); 
    }
    
};


export const dlxkz_file = ref();

export const dlxkz_change = (_, currentFile) => {
    dlxkz_file.value = {
        ...currentFile,
    };
};
export const dlxkz_progress = (currentFile) => {
    dlxkz_file.value = currentFile;
};
export const dlxkz_success = (e) => {
    if(e.response.code == 200){
        form.value.daoluxukezheng = (env.value.VITE_APP_OPEN_PROXY === 'true'? env.value.VITE_APP_BASE_URL : env.value.VITE_APP_BASE_URL) + e.response.data.url;
    }else{
        Message.error(e.response.message); 
    }
    
};

export const refForm = ref("");